package demo.java.springboot.rest;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * https://spring.io/guides/gs/consuming-rest/
 * 
 * @author cailei
 * @date 2018年12月28日
 */
@SpringBootApplication
public class RestApp {
	private static Logger LOG = LogManager.getLogger(RestApp.class);

	/**
	 * @param builder
	 * @return
	 */
	@Bean
	public RestTemplate restTemplate(RestTemplateBuilder builder) {
		return builder.build();
	}

	@Bean
	public User quote(RestTemplate restTemplate) throws Exception {
		User quote = restTemplate.getForObject("http://localhost:8080/user", User.class);
		LOG.info(quote.toString());
		return quote;
	}
	
	public static void main(String args[]) {
		SpringApplication.run(RestApp.class);
	}
}
